home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 1.9 KB | 43 lines | [TEXT/GEOL] |
- Item 1926048 24-Jan-91 18:43PST
-
- From: BERDAHL Amoco Tech, Eric Berdahl,VAR
-
- To: GER.XDV0002 Germany - P1 Ges f Informatik,IVR
- MACAPP.TECH$ MacApp Technical
-
- ------------------------------------------------------------------------------
-
- Sub: Re: RE(?): Pascal '9x… (long)
-
- To All:
- Through some oversight on my part, a critical link in the C++ function
- reference returning discussion did not get sent to MacApp.TECH$. For that I
- appologize. So, for the rest of us, here goes:
-
- The appropriate references (no pun intended) are to §12.1.1c (pp 300-303) and
- §8.4.3 (pp 153-155) of Ellis and Stroustrup _The_Annotated_C++_Reference_.
- What I wrote was reading too much into the C++ language description. If a
- function returns an object, you are safe. AT&Ts implementation of CFront
- generates C code that really returns void and takes a pointer to the
- apporpriate object as a first argument. Thus, the calling function generates a
- temporary variable for the result and passes the pointer. Observe (from Ellis
- and Stroustrup).
- Matrix operator+(const Matrix& a1, const Matrix& a2) {}
- generates something like
- void matrix_add(Matrix* __result, Matrix* a1, Matrix* a2) {}
-
- If, however, the function returns a reference, the language description is
- ambiguous. It does not guarantee anything, so the implication is not to return
- references to local variables. Personally, it is exactly this kind of
- ambiguity that leads me to use reference returns sparingly. Generally, I
- endorse reference returns only as a return from a member function (e.g. TFoo&
- TFoo::FooMethod()) where I can return *this. In this case, reference returning
- is quite convenient and easy. In all other cases, I’m not hot on references
- except as local variables or const arguments.
-
- Skimming the soup,
- Eric Berdahl
- Amoco Technology Company
- AppleLink: BERDAHL
-
-